package com.ssm.zy.controller;

import com.ssm.zy.common.controller.BaseController;
import com.ssm.zy.common.result.Result;
import com.ssm.zy.pojo.Comment;
import com.ssm.zy.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")//评论
public class CommentController extends BaseController {
    @Autowired
    private CommentService commentService;
    //回复评论
    @PostMapping("/commentComment")
    public Result commentComment(@RequestBody Comment comment){
        Integer userId=super.userId;
        int i=commentService.commentComment(comment.getPostId(),comment.getPid(),userId,comment.getCommentContent());
        if (i>0){
            return Result.ok();
        }
        return Result.err();
    }
    // 点赞评论，如果已经点赞就取消点赞
    @PostMapping("/praiseComment")
    public Result praiseComment(@RequestBody Comment comment){
        Integer userId=super.userId;
        int n=commentService.praiseComment(comment.getCommentId(),userId);
        if (n>0){
            return Result.ok();
        }
        return Result.err();
    }
    //删除评论
    @DeleteMapping("/deleteUserPostComment/{commentId}")
    public Result deleteUserPostComment(@PathVariable String commentId) {
        int i=commentService.deleteUserPostComment(Integer.parseInt(commentId));
        if(i==0){
            return Result.err();
        }
        return Result.ok();
    }
}
